package com.yc.pre.utils;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * @author baozhuangyu
 * @Date 2020/11/25  10:34
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserUtil {

//    public static Long getUserId() {
//        HttpServletRequest request = RequestHolder.getRequest();
//        Assert.notNull(request, "获取用户失败");
//        return (Long) request.getAttribute("userId");
//    }

    public static Long getUserId() {
        String token = RequestUtils.getToken();
        return Long.valueOf(JwtUtil.parseJWT(token).getId());
    }

    public static String getUsername() {
        String token = RequestUtils.getToken();
        return JwtUtil.parseJWT(token).getSubject();
    }
}